#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, os
import MySQLdb
import datetime
import time
import calendar
from mysqlClass import mysqlClass
from tool import *
reload(sys)
sys.setdefaultencoding('utf-8')

if __name__ == "__main__":
    DB=mysqlClass()
    date=getDate()
    config=DB.config['local']
    database=config['db']
    dateInt='%s.%s' % (date.replace('-',''),getTimeInt())
    sqlFile="/data/mysql/%s.%s.sql" % (database,dateInt)
    tarFile="/data/mysql/%s.%s.tar.gz" % (database,dateInt)
    logParameter=(config['host'],config['user'],config['passwd'],database,sqlFile)
    os.system("mysqldump -h%s -u%s -p%s %s > %s" % logParameter)
    if os.path.exists(sqlFile):
        os.system("tar -czvf %s %s" % (tarFile,sqlFile))
        os.system('rm -rf %s' % sqlFile)
